home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000218_icon-group-sender _Thu Oct 21 15:23:09 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id PAA04497
  4.     for icon-group-addresses; Thu, 21 Oct 1999 15:17:38 -0700 (MST)
  5. Message-Id: <199910212217.PAA04497@baskerville.CS.Arizona.EDU>
  6. From: "Frank Lhota" <lhotaf@lexma.meitech.com>
  7. To: "Blake Chapman" <blakec@pacbell.net>, <icon-group@optima.CS.Arizona.EDU>
  8. Subject: Re: List subscription insert/removal
  9. Date: Thu, 21 Oct 1999 11:20:28 -0000
  10. X-Priority: 3
  11. X-MSMail-Priority: Normal
  12. X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. I think what Gordon Peterson had in mind was using subscript ranges along
  17. with list catenation, e.g.,
  18.  
  19.     s := s[1:3] ||| [ "x" ] ||| s[3:0]
  20.  
  21. There is probably a more efficient way to do this, but this approach is
  22. certainly straightforward.
  23.  
  24. ----- Original Message -----
  25. From: Blake Chapman <blakec@pacbell.net>
  26. To: <icon-group@optima.CS.Arizona.EDU>
  27. Sent: Thursday, October 21, 1999 2:21 AM
  28. Subject: List subscription insert/removal
  29.  
  30.  
  31. > Icon Project,
  32. >
  33. > I am trying to figure out how to insert a new element into a list,
  34. > and remove an element from the middle of a list (not the end).
  35. > In answer to this question previously Gordon Peterson sent
  36. > a reply.  I tried what he said and it doesn't work.
  37. >
  38. > My original question, that he answered, was
  39. > "I find no routines to pluck one element out of the middle of a list, or
  40. insert
  41. > one in.  Are there such routines?".
  42. >
  43. > His answer was:
  44. > "Perhaps not, since those functions are really pretty trivial (you can use
  45. > subscript ranges to specify sublists, making that kind of thing a simple
  46. > expression).".
  47. >
  48. > I assume he meant that I can insert an element into a list the same way
  49. > I can insert a character into a string variable.  So I tried it, 4 ways;
  50. none
  51. > of them worked, they all produce a run-time error and abort.  Here is
  52. > the program.  Though I use mere charactes or 1-char strings as list
  53. > elements, it is just to try out list manipulation...
  54. >
  55. > procedure main()
  56. >  local s  # it will be a list
  57. >
  58. >  s:= ["a", "b", "c", "d"]
  59. >  WriteL(s)   # this writes "abcd" as it should
  60. >   # Next, I want to insert "x" as a list element between "b" and "c" ....
  61. >   # didn't work:  s[3:3]:="x"
  62. >   # didn't work:  s[3:3] := ["x"]
  63. >   # didn't work:  s[3+:0] := ["x"]
  64. >   s[3+:0] := "x"   # didn't work; I get a run-time error and program abort
  65. >  WriteL(s)
  66. > end
  67. >
  68. > procedure WriteL(L)
  69. >   local i, len
  70. >   len := *L
  71. >   i := 1
  72. >   while  i <= len do  { writes(L[i])  ;  i +:= 1 }
  73. >   write()
  74. > end
  75. >
  76. > I get the following error message when I run the above:
  77. >
  78. > Run-time error 111
  79. > File E:\icon\wsource\sublist.icn; Line 28   [the line:   s[3+:0] := "x" ]
  80. > variable expected
  81. > offending value: list_3 = []
  82. > Traceback:
  83. >    main()
  84. >    {list_3 = [] := "x"} from line 28 in E:\icon\wsource\sublist.icn
  85. >
  86. > Can you tell me how to accomplish what I want?
  87. >
  88. > Thank You,
  89. > Blake Chapman
  90. >
  91. >
  92.  
  93.